package com.kyh.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.UUID;

public class KeyUtil {
    private static String getKey(int length) {

        String uuidStr = UUID.randomUUID().toString().replaceAll("-", "");
        return uuidStr.substring(0, length);
    }

    public static String getKey16() {
        return getKey(16);
    }

    public static String getKey32() {
        return getKey(32);
    }
    
    public static String getNumbersUUID16(){
        //随机生成一位整数
        int random = (int) (Math.random()*9+1);
        String valueOf = String.valueOf(random);
        //生成uuid的hashCode值
        int hashCode = UUID.randomUUID().toString().hashCode();
        //可能为负数
        if(hashCode<0){
            hashCode = -hashCode;
        }
        return valueOf + String.format("%015d", hashCode);
    }

    public static void main(String[] args) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime begin = LocalDateTime.now();
        LocalDateTime end = begin.plus(1, ChronoUnit.DAYS);
        String beginStr = begin.format(dtf);
        String endStr = end.format(dtf);
        System.out.println("beginStr:" + beginStr);
        System.out.println("endStr:" + endStr);

        LocalDate  now = LocalDate.now();
        LocalDateTime oo = now.atStartOfDay();
        System.out.println("oo:" + oo);
    }
}
